package com.sybase.gui;

/*
	Author: Leo
	Creation Date: 8-4-2012
	Creation Time: 7:26 PM
*/

import java.awt.Color;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;

public class CocoaTable {
	// Data member declaration
	static int ROW_NUM = 0;
	protected int rowSize;
	protected int columnSize;
	String[] headerData;
	String[][] tableData;
	ArrayList<String> headerRow;
	ArrayList<String> cocoaRow;
	
	DefaultTableModel cocoaTableModel;
	JTable cocoaTable;
	JTableHeader cocoaTableHeader;
	
	// Constructor
	public CocoaTable() {
		rowSize = 0;
		columnSize = 0;
		headerData = null;
		tableData = null;
		headerRow = null;
		cocoaRow = null;
		
		cocoaTableModel = null;
		cocoaTable = null;
		cocoaTableHeader = null;
	} // End of constructor
	
	public void initComponents() {
		cocoaTableModel = new DefaultTableModel(tableData, headerData);
		cocoaTable = new JTable(cocoaTableModel);
		cocoaTableHeader = cocoaTable.getTableHeader();
		int i, j; // Counter variables		
		
		cocoaTableHeader.setBackground(Color.YELLOW);
		
		for(i = 0; i < rowSize; i++) {
			for(j = 0; j < columnSize; j++) {
				setData(tableData[i][j], i, j);
			}
		}
	} // End of method
	
	public JTable getTable() {
		return cocoaTable;
	}
	
	public String[] setHeaderData() {
		headerData = new String[columnSize];
		int i;
		
		for(i = 0; i < columnSize; i++) {
			headerData[i] = headerRow.get(i);
		}
		
		return headerData;
	} // End of method
	
	public void defineTableData() {
		tableData = new String[rowSize][columnSize];
	} // End of method
	
	public void setTableData() {
		int i; // Counter variable
		
		for(i = 0; i < columnSize; i++) {
			tableData[ROW_NUM][i] = cocoaRow.get(i);
		}
		
		ROW_NUM++;
	} // End of method
	
	public void setData(Object obj, int rowIndex, int columnIndex) {
		cocoaTable.getModel().setValueAt(obj, rowIndex, columnIndex);
	} // End of method
	
	public int getRowSize() {
		return rowSize;
	}
	
	public void setRowSize(int rowSize) {
		this.rowSize = rowSize;
	}
	
	public int getColumnSize() {
		return columnSize;
	}
	
	public void setColumnSize(int columnSize) {
		this.columnSize = columnSize;
	}
	
	public ArrayList<String> getHeaderRow() {
		return headerRow;
	}
	
	public void setHeaderRow(ArrayList<String> headerRow) {
		this.headerRow = headerRow;
	}
	
	public ArrayList<String> getCocoaRow() {
		return cocoaRow;
	}
	
	public void setCocoaRow(ArrayList<String> cocoaRow) {
		this.cocoaRow = cocoaRow;
	}
	
} // End of class